package com.android.xunxian.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.xunxian.utils.UConstants;
import com.android.xunxian.utils.Util;
import com.oa.android.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 上传设置
 * Created by zouqh on 2016/8/10.
 */
public class UpdateSettingActivity extends Activity implements View.OnClickListener{

    @InjectView(R.id.close)
    ImageView close;
    @InjectView(R.id.title_text)
    TextView titleText;
    @InjectView(R.id.ritgh_icon)
    ImageView ritghIcon;
    @InjectView(R.id.ritgh_text)
    TextView ritghText;
    @InjectView(R.id.time)
    EditText time;
    @InjectView(R.id.save)
    TextView save;
    @InjectView(R.id.off)
    ImageView off;
    private String gpstime;
    private String offStr;
    Util util;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.change_time_activity);
        ButterKnife.inject(this);
        close.setOnClickListener(this);
        titleText.setText("上传设置");
        save.setOnClickListener(this);
        off.setOnClickListener(this);
        util=new Util(this);
        gpstime=util.getUser("time");
        offStr=util.getUser("off");
        if (Util.NoNull(gpstime)){
            time.setText(gpstime);
        }else{
            time.setText("30");
        }
        if (Util.NoNull(offStr)&&offStr.equals("1")){
            off.setImageResource(R.drawable.renwu_rwmb_choiceicn_on);
        }else{
            off.setImageResource(R.drawable.renwu_rwmb_choiceicn_off);
        }
//        util.setTime("")
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close:
                finish();
                break;
            case R.id.off:
                offStr=util.getUser("off");
                if (Util.NoNull(offStr)&&offStr.equals("1")){
                    util.setTime("off","");
                    off.setImageResource(R.drawable.renwu_rwmb_choiceicn_off);
                }else{
                    util.setTime("off","1");
                    off.setImageResource(R.drawable.renwu_rwmb_choiceicn_on);
                }
                break;
            case R.id.save:
                if (time.getText().toString().length()>0){
                    int b=Integer.parseInt(time.getText().toString());
                    if (b<10){
                        Toast.makeText(getApplicationContext(),"请输入10秒以上时间",200).show();
                    }else{
                        util.setTime("time",time.getText().toString());
                        UConstants.TIME=b;
                        Toast.makeText(getApplicationContext(),"设置成功",200).show();
                    }
                }else{
                    Toast.makeText(getApplicationContext(),"请输入采集时间",200).show();
                }
                break;
        }
    }
}
